/* jQuery Pre loader
 -----------------------------------------------*/
$(window).load(function () {
    $('.preloader').fadeOut(1000); // set duration in brackets
});


/* Magnific Popup
-----------------------------------------------*/
$(document).ready(function () {
    $('.popup-youtube').magnificPopup({
        type: 'iframe',
        mainClass: 'mfp-fade',
        removalDelay: 160,
        preloader: false,
        fixedContentPos: false,
    });
});


/* Istope Portfolio
-----------------------------------------------*/
jQuery(document).ready(function ($) {

    if ($('.iso-box-wrapper').length > 0) {

        var $container = $('.iso-box-wrapper'),
            $imgs = $('.iso-box img');

        $container.imagesLoaded(function () {

            $container.isotope({
                layoutMode: 'fitRows',
                itemSelector: '.iso-box'
            });

            $imgs.load(function () {
                $container.isotope('reLayout');
            })

        });

        //filter items on button click

        $('.filter-wrapper li a').click(function () {

            var $this = $(this), filterValue = $this.attr('data-filter');

            $container.isotope({
                filter: filterValue,
                animationOptions: {
                    duration: 750,
                    easing: 'linear',
                    queue: false,
                }
            });

            // don't proceed if already selected

            if ($this.hasClass('selected')) {
                return false;
            }

            var filter_wrapper = $this.closest('.filter-wrapper');
            filter_wrapper.find('.selected').removeClass('selected');
            $this.addClass('selected');

            return false;
        });

    }

});


$(document).ready(function () {

    /* Hide mobile menu after clicking on a link
      -----------------------------------------------*/
    $('.navbar-collapse a').click(function () {
        $(".navbar-collapse").collapse('hide');
    });


    /*  smoothscroll
    ----------------------------------------------*/
    $(function () {
        $('#home a, .navbar-default a').bind('click', function (event) {
            var $anchor = $(this);
            $('html, body').stop().animate({
                scrollTop: $($anchor.attr('href')).offset().top-50
            }, 700);
            event.preventDefault();
        });
    });

    $(".rightnav").fadeIn();
    //屏幕滚动函数处理
    // risizetop();
    //
    // function risizetop() {
    //     var top = $(window).height();
    //     if (top >= 500) {
    //         $(".rightnav").fadeIn().css("top", (top - 300) / 2);
    //     } else {
    //         $(".rightnav").hide();
    //     }
    // }

    // $(window).resize(function () {
    //     risizetop()
    // });
    //开关
    $(".ribokey").click(function () {
        if ($(this).attr("data-href") == "true") {
            $(this).find("i").css("background-position", "10px -147px");
            $(".rightbox").css("right", "-50px");
            $(this).attr("data-href", false);
        } else {
            $(".rightbox").css("right", 0);
            $(this).find("i").css("background-position", "10px -191px");
            $(this).attr("data-href", true);
        }
    });
    //各功能事件
    $(".riboli").mouseenter(function () {
        $(this).addClass("active");
    }).mouseleave(function () {
        $(this).removeClass("active");
    });
    $(".obtnlearn").click(function () {
        $(".erweimaoo").removeClass("active");
        $(".erweimaimm").removeClass("shake");
        setTimeout(function () {
            $(".erweimaimm").addClass("shake");
            $(".erweimaoo").addClass("active");
        },400)
    })
    //返回顶部
    $(".gotop").click(function () {
        $('body,html').animate({'scrollTop': 0}, 'slow')
    });

    var swiper = new Swiper('.swiper-container', {
        spaceBetween: 30,
        centeredSlides: true,
        autoplay: {
            delay: 5000,
            disableOnInteraction: false,
        },
        effect: 'fade',
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        on:{
            init: function(){
                swiperAnimateCache(this); //隐藏动画元素
                swiperAnimate(this); //初始化完成开始动画
            },
            slideChangeTransitionEnd: function(){
                swiperAnimate(this); //每个slide切换结束时也运行当前slide动画
                //this.slides.eq(this.activeIndex).find('.ani').removeClass('ani'); 动画只展现一次，去除ani类名
            }
        }
    });
    /* Flexslider
     -----------------------------------------------*/
    $(window).load(function () {
        $('.flexslider').flexslider({
            animation: "slide"
        });
    });


    /* Parallax section
      -----------------------------------------------*/
    function initParallax() {
        $('#about').parallax("100%", 0.1);
        $('#feature').parallax("100%", 0.3);
        $('#video').parallax("100%", 0.2);
        $('#menu').parallax("100%", 0.3);
        $('#team').parallax("100%", 0.3);
        $('#gallery').parallax("100%", 0.1);
        $('#contact').parallax("100%", 0.2);
    }

    initParallax();


    /* Nivo lightbox
      -----------------------------------------------*/
    $('#gallery .col-md-4 a').nivoLightbox({
        effect: 'fadeScale',
    });


    /* wow
    -------------------------------*/
    new WOW({mobile: false}).init();

});
